<%@ page language="java" import="java.util.*,java.text.*,java.io.*" pageEncoding="utf-8"%>
<%@page import="issuedfileaction.DBConnection;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>       
    <title>查询未识别文件名</title>    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>  
  <body> 
  <%
    String rowid="";
    String FDir="";
    String Mfilename="";
    String sfilename="";
    SimpleDateFormat sdft=new SimpleDateFormat("yyyy-MM-dd");
    String Datetime=sdft.format(new Date());
     try{
         rowid=new String(request.getParameter("rowid").getBytes("ISO-8859-1"),"utf-8");
         rowid=rowid.trim();
     }catch(Exception e){
         rowid="";
     }
     try{
         FDir=new String(request.getParameter("FDir").getBytes("ISO-8859-1"),"utf-8");
         FDir=FDir.trim();
     }catch(Exception e){
         FDir="";
     }
     try{
         //Mfilename=new String(request.getParameter("Mfilename").getBytes("ISO-8859-1"),"utf-8");
         Mfilename=new String(request.getParameter("Mfilename").getBytes("ISO-8859-1"),"gbk");
         Mfilename=Mfilename.trim();
     }catch(Exception e){
         Mfilename="";
     }
     try{
         //sfilename=new String(request.getParameter("sfilename").getBytes("ISO-8859-1"),"utf-8");
         sfilename=new String(request.getParameter("sfilename").getBytes("ISO-8859-1"),"gbk");
         sfilename=sfilename.trim();
     }catch(Exception e){
         sfilename="";
     }     
     //移动文件
     Properties propertyport = new Properties();
     String dir=DBConnection.class.getResource("/").getPath().trim()+"\\DB.properties"; 
     dir=dir.replace("%20"," "); 		
     propertyport.load(new FileInputStream(dir));
     String moveFileDir=propertyport.getProperty("MoveFileDir");
     //NoSplitFolder=OrgData
     //SplitFolder=GroupData
     String NoSplitFolder=propertyport.getProperty("NoSplitFolder");
     String SplitFolder=propertyport.getProperty("SplitFolder");
     if(FDir.trim().toUpperCase().contains(NoSplitFolder.trim().toUpperCase())){
        moveFileDir=moveFileDir+NoSplitFolder+"/";
     }else if(FDir.toUpperCase().contains(SplitFolder.trim().toUpperCase())){
        moveFileDir=moveFileDir+SplitFolder+"/";
     }     
     File SFileDir=new File(FDir,sfilename);
     File DFileDir=new File(moveFileDir,Mfilename);
     FileInputStream from = new FileInputStream(SFileDir);
	 FileOutputStream to = new FileOutputStream(DFileDir);//auto
     //SFileDir.renameTo(DFileDir);//移文件
	 byte[] buffer = new byte[1024];
	 int bytes_read;
	 while ((bytes_read = from.read(buffer)) != -1) {
		  to.write(buffer, 0, bytes_read);
	 }
	 from.close();
	 to.close();
	 DFileDir.setLastModified(SFileDir.lastModified());
	 SFileDir.delete();     
     //移动完成     
     String StrSQL="update dtunknowfile set dn_mfilename='"+Mfilename.trim()+"' where dn_id='"+rowid.trim()+"'";     
     DBConnection db=new DBConnection();     
     db.UpdateExec(StrSQL); 
     //String msg="alert('文件名修改成功!');"; 
	 //response.setContentType("text/html; charset=utf-8");
	 //response.setHeader("Cache-Control", "no-cache");
	 //PrintWriter pw = response.getWriter();
	 //pw.write("<SCRIPT TYPE='text/javascript'>" + msg + "</SCRIPT>");
	 //pw.close();             		    	  
	 //response.sendRedirect("ViewUnKnowFile.jsp");                        
  %>
  </body>
</html>
